import java.util.*;
class calculator{

public static char[] revChar(char[] chArray){
	char[] res = new char[chArray.length];
	int last = chArray.length-1;
	for(int i=0; i<chArray.length; i++){
		res[last] = chArray[i];
		last--;
	}
	return res;
}
public static int[] revInt(int[] chArray){
	int[] res = new int[chArray.length];
	int last = chArray.length-1;
	for(int i=0; i<chArray.length; i++){
		res[last] = chArray[i];
		last--;
	}
	return res;
}
public static int[] even(int from,int to ){
int[] num=new int[5];
int i=0;
for(int j=from;j<to/2;j++){
num[j]=i;
i=i+2;
}
return num;
}
/*prime num
public static int[] prime(int[] num)
{
	for(int i=1;i<num.length;i++)
	{
	for(int j=2; j<i; j++){
	
           if(i%j != 0)
			   num[i]=i;
		   
		  }
		  }
			   return num;
}
*/
//sum of all elements in array
public static int sum(int[] num){
int result=0;
for(int i=0;i<num.length;i++){
result=num[i]+result; 
}
return result;
}
//fibonocci
public static int[] generatefib(int n) {
int[] fib=new int[n];
	fib[0]=0;
	fib[1]=1;
	for(int i=2;i<n;i++)
	{
	  fib[i]=fib[i-1]+fib[i-2];
	}
	return fib;
 }
 //odd number
 public static int[] odd(int from,int to ){
int[] num=new int[5];
int i=1;
for(int j=from;j<to/2;j++){
num[j]=i;
i=i+2;
}
return num;
}
public static int[]randgen(int n){
int[] arr=new int[n];
for(int i=0;i<10;i++){
arr[i]=(int)Math.random()*100000;
}
return arr;
}
public static void printCharArray(char[] c){
	for(int i=0; i<c.length; i++)
		System.out.println(c[i]);
}
public static void printIntArray(int[] c){
	for(int i=0; i<c.length; i++)
		System.out.println(c[i]);
}
public static void printDoubleArray(double[] c){
	for(int i=0; i<c.length; i++)
		System.out.println(c[i]);
}
public static long calTime(){
	long start=System.currentTimeMillis();
	int[] arr=new int[100000];
	long end=System.currentTimeMillis();
	return end-start;
} 
public static void printIntArray(int[][] c){
    System.out.println("printing the elements\n");
	for(int i=0; i<c.length; i++){
	for(int j=0;j<c.length;j++){
		System.out.println(c[i][j]+" ");
	}
	}
}
public static int[][] randomGen(){
//multidimentional array
	int[][] arr1=new int[8][10];
	
	System.out.println("row="+arr1.length+"\t col="+arr1[0].length);
	for(int i=0;i<arr1.length;i++){
	 for(int j=0;j<arr1.length;j++){
	  arr1[i][j]=(int)(Math.random()*1000);
	}
	}
	return arr1;
}
//addition of matrix
public static int[][] addMatrix(){
	int[][] mat1={{1,2},
				  {3,4}};
	int[][] mat2={{1,2},
				  {3,4}};	
	int[][] mat3=new int[2][2];
				  
	for(int i=0;i<mat1.length;i++){
	 for(int j=0;j<mat2.length;j++){
	 mat3[i][j]=mat1[i][j]+mat2[i][j];
	 }
	}
	return mat3;
}
//matrix multiplication
public static int[][] multipyMatrix(){
	int[][] mat1={{1,2},
				  {3,4}};
	int[][] mat2={{1,2},
				  {3,4}};	
	int row=mat1.length;
	int col=mat2[0].length;
	int[][] mat3=new int[row][col];			  
	for(int i=0;i<row;i++){
	 for(int j=0;j<col;j++){
	 mat3[i][j]=0;
	 for(int k=0;k<row;k++){ 
	 mat3[i][j]+=mat1[i][k]*mat2[k][j];
	 }
	}
	}
	return mat3;
}
//create 2*3 and 3*2 at the time of declaration
public static void Matrix(){
	int[][] mat1=new int[2][3];
	int[][] mat2=new int[3][2];
	int count=mat1.length*mat1[0].length;
	System.out.println("total no of variables in matrix 1 is:"+count);
}
//sum of all elements in array
public static void MatrixSum(){
	int[][] arr1={{2,2,2,2,2},{2,2,2,2,2}};
	System.out.println("row="+arr1.length+"\t col="+arr1[0].length);
	int count=0;
	for(int i=0;i<arr1.length;i++){
	 for(int j=0;j<arr1[0].length;j++){
	  count=arr1[i][j]+count;
	}
	}
	System.out.println("sum="+count);
}
	//multidimentional array for sum of rows and sum of columns separately
	public static void printArray(int[] c){
	for(int i=0;i<c.length;i++)
	System.out.println(" "+c[i]);
}	
	
public static void sumRowCol(){
	int[][] arr1={{2,2,2,2,2},{2,2,2,2,2}};
	System.out.println("row="+arr1.length+"\t col="+arr1[0].length);
	int[] r=new int[2];
	int[] c=new int[5];
	r[0]=0;
	for(int i=0;i<arr1.length;i++){
	for(int j=0;j<arr1[0].length;j++){
	r[i]=arr1[i][j]+r[i];
	
	}
	}
	printArray(r);
	c[0]=0;
	for(int i=0;i<5;i++){
	for(int j=0;j<2;j++){
	c[i]=arr1[i][j]+c[i];
	}
	}
	printArray(c);
}
}